#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
using namespace std; using pii = pair<int,int>;
constexpr int N=6e6+5;
class DSU{
	int n,fa[N];
public:
	void init(int _n) { n=_n; For(i,1,n) fa[i]=i; }
	int getfa(int x) { return x==fa[x]?x:(fa[x]=getfa(fa[x])); }
	void merge(int x,int y) { fa[getfa(y)]=getfa(x); }
}R,C;
int n,m,K,S,T,vis[N],dis[N],q[N*4],h,t; bool mp[N];
int ID(int i,int j) { return (i-1)*m+j; }
pii Get(int u) { return pii((u-1)/m+1,(u-1)%m+1); }
void Erase0(int u){
	assert(u<=n*m);
	auto [i,j]=Get(u);
	if(j==m) R.merge(0,u); else R.merge(u+1,u);
}
void Erase1(int u){
	assert(u<=n*m);
	auto [i,j]=Get(u);
	if(i==n) C.merge(0,u); else C.merge(u+m,u);
}
void work0(int u,int d){
	assert(u<=n*m);
	for(int v=R.getfa(u);v&&v<u+K;v=R.getfa(v)){
		if(dis[v]==-1||dis[v]>d+1) { dis[v]=d+1; q[t++]=v; }
		Erase0(v);
	}
}
void work1(int l,int r,int d){
	assert(l<=r&&r<=n*m);
	for(int v=C.getfa(l);v&&v<=r;v=C.getfa(v)){
		work0(v,d); Erase1(v);
	}
}
int main(){
	Fin("stamp.in"); Fout("stamp.out");
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n>>m>>K;
	{ int x,y; cin>>x>>y; S=ID(x,y); }
	{ int x,y; cin>>x>>y; T=ID(x,y); }
	For(i,1,n){
		static char str[N]; cin>>str;
		For(j,1,m) mp[ID(i,j)]=(str[j-1]=='#');
	}
	R.init(n*m); C.init(n*m);
	For(i,1,n*m) dis[i]=-1;
	h=N*2,t=N*2; q[t++]=S; dis[S]=0;
	while(h<t){
		int u=q[h++]; if(vis[u]) continue; else vis[u]=1;
		auto [x,y]=Get(u);
		// LOG("u=%d: dis=%d\n",u,dis[u]);
		for(auto [x0,y0]:{pii(x-1,y),pii(x+1,y),pii(x,y-1),pii(x,y+1)}){
			if(x0==0||x0==n+1||y0==0||y0==m+1||mp[ID(x0,y0)]) continue;
			int v=ID(x0,y0); if(dis[v]!=-1&&dis[v]<=dis[u]) continue;
			dis[v]=dis[u]; q[--h]=v;
		}
		int l=max(1,x-K+1),r=min(n,x+K-1);
		work1(ID(l,max(1,y-K)),ID(r,max(1,y-K)),dis[u]);
		if(y!=m) work1(ID(l,y+1),ID(r,y+1),dis[u]);
		l=max(1,x-K); r=min(n,x+K);
		work1(ID(l,max(1,y-K+1)),ID(r,max(1,y-K+1)),dis[u]);
		work1(ID(l,y),ID(r,y),dis[u]);
	}
	cout<<dis[T]<<'\n';
	return 0;
}